package net.zjitc.list.web;

import net.zjitc.list.dao.UserDao;
import net.zjitc.list.dao.UserDaoImpl;
import net.zjitc.list.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Administrator
 * @Date 2020/6/16 15:56
 * 查找联系人Servlet，用于修改的数据回显
 **/
@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*1.获取请求参数id
        * 2.调用dao方法，根据id得到User对象
        * 3.将User对象保存在request域
        * 4.转发到update.jsp(页面取出request域中的信息，显示数据）*/
        String ids = request.getParameter("id");
        int id=Integer.parseInt(ids);
        UserDao dao=new UserDaoImpl();
        User user=dao.findByUser(id);
        /*保存在request域*/
        request.setAttribute("user",user);
        request.getRequestDispatcher("/list/update.jsp").forward(request,response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
